package com.hibernate.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.javacommon.base.BaseEntity;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import cn.org.rapid_framework.util.DateConvertUtils;

/**
 * 
 */

@Entity
@Table(name = "REPORT_KEY_PAGE")
public class ReportKeyPage extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "关键页面";
	public static final String ALIAS_ID = "ID";
	public static final String ALIAS_AD_OWNER_ID = "广告客户ID";
	public static final String ALIAS_NAME = "页面名称";
	public static final String ALIAS_URL = "页面URL";
	public static final String ALIAS_TYPE = "页面类型";
	public static final String ALIAS_CREATION_TIME = "创建时间";
	public static final String ALIAS_STATUS = "状态";
	
	//date formats
	public static final String FORMAT_CREATION_TIME = DATE_FORMAT;
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
    /**
     * ID       db_column: ID 
     */ 	
	
	private Long id;
    /**
     * 广告客户ID       db_column: AD_OWNER_ID 
     */ 	
	@NotNull 
	private Long adOwnerId;
    /**
     * 页面名称       db_column: NAME 
     */ 	
	@NotBlank @Length(max=200)
	private java.lang.String name;
    /**
     * 页面URL       db_column: URL 
     */ 	
	@NotBlank @Length(max=300)
	private java.lang.String url;
    /**
     * 页面类型       db_column: TYPE 
     */ 	
	@NotBlank @Length(max=1)
	private java.lang.String type;
    /**
     * 创建时间       db_column: CREATION_TIME 
     */ 	
	@NotNull 
	private java.util.Date creationTime;
    /**
     * 状态       db_column: STATUS 
     */ 	
	@NotBlank @Length(max=1)
	private java.lang.String status;
	//columns END


	public ReportKeyPage(){
	}

	public ReportKeyPage(
		Long id
	){
		this.id = id;
	}

	

	public void setId(Long value) {
		this.id = value;
	}
	
	@Id
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "native") 
	@Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true, length = 20)
	public Long getId() {
		return this.id;
	}
	
	@Column(name = "AD_OWNER_ID", unique = false, nullable = false, insertable = true, updatable = false, length = 20)
	public Long getAdOwnerId() {
		return this.adOwnerId;
	}
	
	public void setAdOwnerId(Long value) {
		this.adOwnerId = value;
	}
	
	@Column(name = "NAME", unique = false, nullable = false, insertable = true, updatable = true, length = 200)
	public java.lang.String getName() {
		return this.name;
	}
	
	public void setName(java.lang.String value) {
		this.name = value;
	}
	
	@Column(name = "URL", unique = false, nullable = false, insertable = true, updatable = true, length = 300)
	public java.lang.String getUrl() {
		return this.url;
	}
	
	public void setUrl(java.lang.String value) {
		this.url = value;
	}
	
	@Column(name = "TYPE", unique = false, nullable = false, insertable = true, updatable = true, length = 1)
	public java.lang.String getType() {
		return this.type;
	}
	
	public void setType(java.lang.String value) {
		this.type = value;
	}
	
	@Transient
	public String getCreationTimeString() {
		return DateConvertUtils.format(getCreationTime(), FORMAT_CREATION_TIME);
	}
	public void setCreationTimeString(String value) {
		setCreationTime(DateConvertUtils.parse(value, FORMAT_CREATION_TIME,java.util.Date.class));
	}
	
	@Column(name = "CREATION_TIME", unique = false, nullable = false, insertable = true, updatable = false, length = 7)
	public java.util.Date getCreationTime() {
		return this.creationTime;
	}
	
	public void setCreationTime(java.util.Date value) {
		this.creationTime = value;
	}
	
	@Column(name = "STATUS", unique = false, nullable = false, insertable = true, updatable = true, length = 1)
	public java.lang.String getStatus() {
		return this.status;
	}
	
	public void setStatus(java.lang.String value) {
		this.status = value;
	}
	
	
//	private Set reportKeyPageAccesss = new HashSet(0);
//	public void setReportKeyPageAccesss(Set<ReportKeyPageAccess> reportKeyPageAccess){
//		this.reportKeyPageAccesss = reportKeyPageAccess;
//	}
//	
//	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "reportKeyPage")
//	public Set<ReportKeyPageAccess> getReportKeyPageAccesss() {
//		return reportKeyPageAccesss;
//	}
	
//	private AdOwner adOwner;
//	public void setAdOwner(AdOwner adOwner){
//		this.adOwner = adOwner;
//	}
//	
//	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
//	@JoinColumns({
//		@JoinColumn(name = "AD_OWNER_ID",nullable = false, insertable = false, updatable = false) 
//	})
//	public AdOwner getAdOwner() {
//		return adOwner;
//	}

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("Id",getId())
			.append("AdOwnerId",getAdOwnerId())
			.append("Name",getName())
			.append("Url",getUrl())
			.append("Type",getType())
			.append("CreationTime",getCreationTime())
			.append("Status",getStatus())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getId())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof ReportKeyPage == false) return false;
		if(this == obj) return true;
		ReportKeyPage other = (ReportKeyPage)obj;
		return new EqualsBuilder()
			.append(getId(),other.getId())
			.isEquals();
	}
	@Transient
	@Override
	public String getTarget() {
		// TODO Auto-generated method stub
		return "关键页面";
	}
	@Transient
	@Override
	public Long getTargetId() {
		// TODO Auto-generated method stub
		return getId();
	}
	@Transient
	@Override
	public String getTargetName() {
		// TODO Auto-generated method stub
		return null;
	}
}

